<template>
    <div class="subjects">
        <topBar :title="title"></topBar>
        <div class="center">
            <div class="left">
                <div>
                    <div class="square"></div>
                    <div class="html">公众：{{gzContent}}</div>
                </div>
                <div>
                    <div class="square"></div>
                    <div class="html">政企：{{zqContent}}</div>
                </div>
            </div>
            <div class="right">
                <el-table
                    border
                    style="width: 100%"
                    :span-method="objectMethod"
                    :cell-style="{padding: '0px'}"
                    :header-cell-style="{background: '#0070C0', color: '#ffffff',padding: '0',height:'26px'}"
                    :data="tableData">
                    <el-table-column
                        label="科目类别1"
                        prop="class1"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column
                        label="科目类别2"
                        prop="class2"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column
                        label="科目类别3"
                        prop="verticalIndexName"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column
                        label="公众累计同比"
                        prop="gztbYearLjInreaseAmt"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column
                        label="政企累计同比"
                        prop="zqtbYearLjInreaseAmt"
                        align="center"
                    >
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</template>

<script>
import topBar from "./topBar";
import {
  subjectComparison,subjectContent
} from "@/api/codeIncome/analysis";
export default {
    name: "customerType",
    components: {
        topBar
    },
    data(){
        return{
            title: '码号收入 – 公众政企科目同比',
            tableData: [],
            spanArr1: [],
            spanArr2: [],
            gzContent: '',
            zqContent: ''
        }
    },
    props: {
        searchData: {
        type: Object,
        default: {},
        },
    },
    watch: {
        searchData: {
        handler(newName) {
            this.getData()
            this.getTextData()
        },
        deep: true,
        },
    },
    created() {},
    mounted() {
        this.getData()
        this.getTextData()
    },
    methods: {
        getData() {
            subjectComparison({
                code: 2,
                acctMonth:this.searchData.acctMonth,
                areaId: this.searchData.areaId
            }).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data
                    let contactDot = 0;
                    let spanArr1 = [];
                    let contactDot1 = 0;
                    let spanArr2 = []
                    this.tableData.forEach((item, index) => {
                        if (index === 0) {
                            spanArr1.push(1)
                            spanArr2.push(1)
                        } else {
                            if (item.class1 === this.tableData[index - 1].class1) {
                                spanArr1[contactDot] += 1;
                                spanArr1.push(0)
                            }else {
                                contactDot = index
                                spanArr1.push(1)
                            }
                            if (item.class2 === this.tableData[index - 1].class2) {
                                spanArr2[contactDot1] += 1;
                                spanArr2.push(0)
                            }else {
                                contactDot1 = index
                                spanArr2.push(1)
                            }
                        }
                    })
                    this.spanArr1 = spanArr1;
                    this.spanArr2 = spanArr2
                }
            })
        },
        objectMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
                if(this.spanArr1[rowIndex]){
                    return {
                        rowspan:this.spanArr1[rowIndex],
                        colspan:1
                    }
                }else{
                    return {
                        rowspan: 0,
                        colspan: 0
                    }
                }
            }
            if (columnIndex === 1) {
                if (this.spanArr2[rowIndex]) {
                    return {
                        rowspan:this.spanArr2[rowIndex],
                        colspan:1
                    }
                } else {
                    return {
                        rowspan: 0,
                        colspan: 0
                    }
                }
            }
        },
        getTextData() {
            subjectContent({
                code: 2,
                acctMonth:this.searchData.acctMonth,
                areaId: this.searchData.areaId
            }).then((res) => {
                this.gzContent = res.data.gzContent
                this.zqContent = res.data.zqContent
            })
        }
    }
}
</script>

<style scoped>
.subjects {
    box-sizing: border-box;
    padding: 20px;
    box-shadow: 0px 0px 10px 1px rgb(0 0 0 / 15%);
}
</style>

<style scoped lang="scss">
.subjects{
    margin-top: 20px;
    height: 100%;
}
.center{
    box-sizing: border-box;
    padding: 0 20px;
    margin-top: 10px;
    .left{
        width: 100%;
        > div {
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }
    }
    .right {
        width: 100%;
        > div {
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }
    }
    .square{
        margin-top: 15px;
        margin-right: 10px;
        width: 10px;
        height: 10px;
        background: #c00000;
        transform: rotate(45deg);
    }
    .html {
        flex: 1;
        font-size: 18px;
        color: black;
        letter-spacing: 1px;
        line-height: 36px;
    }
}
</style>
